﻿using PicoContainer.Defaults;
using XEvolve.Core.Runtime;
using XEvolve.Core.SPI;
using IExtensionRegistry=XEvolve.Core.SPI.IExtensionRegistry;

namespace XEvolve.Core.Pico
{
    public class XEvolvePlatformProvider : IPlatformProvider
    {
        private readonly DefaultPicoContainer context;

        public XEvolvePlatformProvider()
        {
            context = new DefaultPicoContainer(new XComponentAdapterFactory(true));
            ExtensionRegistry = new PicoBasedExtensionRegistry(context);
            ServiceRegistry = new PicoBasedServiceRegistry(context);

            ServiceRegistry.RegisterService(typeof (Runtime.IExtensionRegistry), ExtensionRegistry);
            ServiceRegistry.RegisterService(typeof (Runtime.IServiceLocator), ServiceRegistry);
        }

        public IExtensionRegistry ExtensionRegistry { get; private set; }

        public IServiceRegistry ServiceRegistry { get; private set; }

        public IServiceLocator ServiceLocator
        {
            get { return (IServiceLocator) ServiceRegistry; }
        }
    }
}